<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href='jsPlugin/layui/css/layui.css' rel=stylesheet />
<link rel="stylesheet" type="text/css"
	href="jsPlugin/semantic/semantic.min.css">
<link href='css/form-style.css' rel='stylesheet' />
<script src="jsPlugin/laydate/laydate.js"></script>
<script src='js/jquery.min.js'></script>
<script src="jsPlugin/layui/layui.js"></script>
<script src="js/util.js"></script>
<script src="jsPlugin/jqprint/jQuery.print.js"></script>
</head>
<body>
	<div class="form-div">

		<div class="ui segment no-print">
			<form class="layui-form layui-form-pane layui-box">
				<div class="layui-form-item">
					<label class="layui-form-label">选择日期</label>
					<div class="layui-input-inline">
						<input class="layui-input" id="start" placeholder="开始日"
							onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD'})">
					</div>

					<div class="layui-input-inline">
						<input class="layui-input" id="end" placeholder="截止日"
							onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD'})">
					</div>


				</div>
			</form>
			<c:forEach items="${type}" var="item">
				<button class="layui-btn layui-btn-normal"
					onclick="findCondiction('${item.value }')">${item.text }</button>
			</c:forEach>
			<!-- <button class="layui-btn layui-btn-normal"
					onclick="findCondiction('S')">省市领导批示</button>
			<button class="layui-btn layui-btn-normal"
					onclick="findCondiction('X')">肖局长批示</button> -->
		</div>

		<div class="layui-tab layui-tab-brief">
			<ul class="layui-tab-title">
				<li class="layui-this">承办单位</li>
				<li>来文单位</li>
			</ul>
			<div class="layui-tab-content print">
				<div class="layui-tab-item layui-show">
					<jsp:include page="../table/supervise_data_require.jsp"></jsp:include>
				</div>
				<div class="layui-tab-item ">
					<jsp:include page="../table/supervise_data_rec.jsp"></jsp:include>
				</div>

			</div>
		</div>
	</div>
</body>
<script>

	layui.use(['form', 'laydate', 'element'], function() {
		var form = layui.form(), element = layui.element();
	});
	
	//渲染页面
	var render = function(res){
        var ele = '';
		if(res){
				$(res).each(function(j, jtem){
						var sum = jtem.sum == null ? '':jtem.sum;
						var done = jtem.done == null ? '':jtem.done;
						var doing = jtem.doing == null ? '':jtem.doing;
						ele += "<tr>";
						ele += '<td >'+formartDic(jtem.user_organiz_type, 'CODE_ORGANIZ_TYPE')+'</td>';
						ele += '<td >'+jtem.user_organiz_name+'</td>';
						ele += '<td >'+sum +'</td>';
						ele += '<td >'+done+'</td>';
						ele += '<td >'+doing +'</td>';
						ele += '<td > </td>';
						ele += "</tr>";
				});
		}
		
		$('#supervise_list01 tbody').html(ele);
		
		//合并单元格
        $('#supervise_list01 tbody').rowspan(0);

	};
	
	var _render = function(res){
		  var ele = '';
			if(res){
				
					$(res.list).each(function(j, jtem){
							 var l = res.list.length;
							l=l-j;
							var d = new Date(Date.parse(jtem.rec_time.replace(/-/g,"/"))).format("MM月dd日");
							ele += "<tr>";
							ele += '<td >'+l+'</td>';
							ele += '<td >'+d+'</td>';
							ele += '<td >'+formartDic(jtem.rec_organiz_id, 'CODE_REC_ORGANIZS')+'</td>';
							ele += '<td >'+jtem.rec_sno+'</td>';
							ele += '<td >'+jtem.info_title+'</td>';
							ele += '<td ><pre>'+jtem.info_con+'</pre></td>';
							ele += '<td >'+formartDic(jtem.info_type, 'CODE_EVENT_SUPERVISE')+'</td>';
							ele += '<td >'+formartDic(jtem.progress_status, 'CODE_HANDLE_STATIUS')+'</td>';
							var _con = findprogressinfo(jtem.progress_id);
							ele += '<td >'+_organiz(jtem.require_organiz_id)+'</td>';
							ele += '<td >'+_con+'</td>';
							ele += "</tr>"; 
						/* var l = res.list.length;
						l=l-j;
						var d = new Date(Date.parse(jtem.rec_time.replace(/-/g,"/"))).format("MM月dd日");
						var con = jtem.progress_info_con ? jtem.progress_info_con : '';
						ele += "<tr>";
						//ele += '<td >'+l+'</td>';
						ele += '<td >'+d+'</td>';
						ele += '<td >'+formartDic(jtem.rec_organiz_id, 'CODE_REC_ORGANIZS')+'</td>';
						ele += '<td >'+jtem.rec_sno+'</td>';
						ele += '<td >'+jtem.info_title+'</td>';
						ele += '<td >'+jtem.info_con+'</td>';
						ele += '<td >'+formartDic(jtem.info_type, 'CODE_EVENT_SUPERVISE')+'</td>';
						ele += '<td >'+formartDic(jtem.progress_status, 'CODE_HANDLE_STATIUS')+'</td>';
						ele += '<td >'+jtem.cuser_organiz_name+'</td>';
						//var _con = findprogressinfo(jtem.progress_id);
						ele += '<td >'+formartDic(jtem.progress_info_status, "CODE_HANDLE_STATIUS")+'</td>';
						ele += '<td ><pre style="word-wrap: break-word;word-break: break-all;">'+con+'</pre></td>';
						ele += "</tr>"; */
					});
					$('#supervise_list02 tbody').html(ele);
				      //合并单元格
			        $('#supervise_list02 tbody td tbody').each(function(j, jtem){
			        	$(jtem).rowspan(0);
			        });
			}
			
			//合并单元格
	  /*       $('#supervise_list01 tbody').rowspan(0);
	        $('#supervise_list01 tbody').rowspan(1);
	        $('#supervise_list01 tbody').rowspan(2);
	        $('#supervise_list01 tbody').rowspan(3);
	        $('#supervise_list01 tbody').rowspan(4);
	        $('#supervise_list01 tbody').rowspan(5);
	        $('#supervise_list01 tbody').rowspan(6);
	        $('#supervise_list01 tbody').rowspan(7);
	        $('#supervise_list01 tbody').rowspan(8); */
	};
	function findprogressinfo(progress_id){
        var arr="";
		$.ajaxSettings.async=false;
		$.getJSON("supervise/progress/info/query3", { num:1, size:100000, progress_id:progress_id }, function(data){
		    var l = data.list;
		      for(var i=0; i<l.length;i++){
				if(l[i].progress_info_con == null){l[i].progress_info_con = '';}
				if(i>0){
					if(l[i].cuser_organiz_name != l[i-1].cuser_organiz_name){
					arr += '<strong>'+l[i].cuser_organiz_name+'：'+ formartDic(l[i].progress_info_status, 'CODE_HANDLE_STATIUS')+'</strong>';
					}
				}else{
					arr += '<strong>'+l[i].cuser_organiz_name+'：'+ formartDic(l[i].progress_info_status, 'CODE_HANDLE_STATIUS')+'</strong>';
				}
				arr += '<pre style="word-wrap: break-word;word-break: break-all;">'+ l[i].progress_info_con +'</pre>';
		      }
		});
		$.ajaxSettings.async=true;

		return arr;
	}
	function findCondiction(type){ 
		layui.use('layer', function() {
			
			var layer = layui.layer;
			var abc = "";
			if(type=='LEADER_APPROVAL_TYPE_01'){
				$('#data_rec').text('省市领导批示件登记汇总表');
				$('#data_require').text('省市领导批示件办理情况统计表');
			}else if(type=='LEADER_APPROVAL_TYPE_02'){
				$('#data_rec').text('肖春局长批示件登记汇总表');
				$('#data_require').text('肖春局长批示件办理情况统计表');
			}
			
			if($('#start').val() && $('#end').val() && type){
				 abc = layer.load(0, { time: 10 * 1000 });
				/* var start = new Date($('#start').val().replace(/-/g,"/"));
				var end = new Date($('#end').val().replace(/-/g,"/"));	 */
				//var fs = new Date($('#start').val());
				//var fe = new Date($('#end').val());
				var start = $('#start').val();
				var end = $('#end').val();
				//var str = getYearWeek(start);
				//$('table caption').text(start.getFullYear()+'年 第'+str+'周  ('+start.format('MM月dd日 ')+'至'+end.format('MM月dd日')+')');
				 //start:Math.round(start.getTime()/1000)
				$.getJSON("supervise/info/getcountfororganiz", {start:start, end:end, type:type}, function(data){
					
					render(data);
					
					layer.close(abc);
					
				});
				$.getJSON("supervise/info/getcountforall", { num:1, size:100000, start:start, end:end, type:type}, function(data){
					
					_render(data);
					
					layer.close(abc);
					
				});
			}else{
					 layer.msg('请完整输入日期范围', {
	                     icon: 5,
	                     anim: 6
	                 });
			}
		});
	}
	function _isnan(ct) {
	    if (ct == 'NaN' || ct == '' || ct == 'underfined') {
	        return null;
		}
	}
	

	/**jqprint 实现网页局部打印
	 ***/
	    function JQprint() {
	        //Print ele4 with custom options
	        $(".print").print({
	            //Use Global styles
	            globalStyles: true,
	            //Add link with attrbute media=print
	            mediaPrint: true,
	            //importCSS: true,
	            //Custom stylesheet
	            //stylesheet : $('#basepath').val()+"css/login.jsp.css",
	            //Print in a hidden iframe
	            iframe: true,
	            //Don't print this
	            noPrintSelector: ".no-print"
	            //Add this at top
	            // prepend : "兰州市公安局<br/>",
	            //Add this on bottom
	            //append: '<br/><footer align="center">兰州市公安局</footer>'
	        });
	    };
	    // Fork https://github.com/sathvikp/jQuery.print for the full list of options	
	    
	     // JavaScript Document
	  //功能:导出多个表格到EXCEL或者ET
	  //调用方法：toExcel('要导出的表格ID,以|分隔多个表格','输出到excel中的工作薄名称','导出的方式，0为不带格式，1为带格式','要导出的列数')
	  var idTmr = ""; 
	  function Cleanup() { 
	  window.clearInterval(idTmr); 
	  CollectGarbage(); 
	  } 
	   
	  function toExcel(tableId,sheetname,method,cols){
		  
	      if(!confirm("确认导出数据到EXCEL?")){return false;}
	      
	      /**
	      *
		  *	JS设置IE可信站点及ActiveX设置
		      通过网页修改activex安全设置，添加信任站点，禁用弹出窗口阻止程序
		      信任站点的注册表项：HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/ZoneMap/Ranges/Range[*]
		      ActiveX的注册表项：HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/[0-4]/[*]
		      [0-4]
		      值 设置
		      ------------------------------
		      0 我的电脑
		      1 本地 Intranet 区域
		      2 受信任的站点区域
		      3 Internet 区域
		      4 受限制的站点区域
		      [*]
		      1001 下载已签名的 ActiveX 控件
		      1004 下载未签名的 ActiveX 控件
		      1200 运行 ActiveX 控件和插件
		      1201 对没有标记为安全的 ActiveX 控件进行初始化和脚本运行
		      1405 对标记为可安全执行脚本的 ActiveX 控件执行脚本
		      2201 ActiveX 控件自动提示
		     弹出窗口阻止程序的注册表项：HKEY_CURRENT_USERHKCU/Software/Microsoft/Internet Explorer/New Windows/PopupMgr
	      */
	     // var WshShell=new ActiveXObject("WScript.Shell");
	      //修改IE ActiveX安全设置:3Internet区域
	     //WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1201","0","REG_DWORD");
	      
	      var tables=tableId.split("|");
	      for(var n=0;n<tables.length;n++){
	          if(!document.getElementById(tables[n])){
	              alert("表格"+tables[n]+"不存在,请检查是否有数据输出");
	              return false;
	          }
	      }
	      try{
	          var oXL = new ActiveXObject("excel.Application");
	      }catch(e1){
	          try{
	              var oXL = new ActiveXObject("et.Application");
	          }catch(e2){
	              alert(e2.description+"\n\n\n要使用EXCEL对象，您必须安装Excel电子表格软件\n或者,需要安装Kingsoft ET软件\n\n同时浏览器须使用“ActiveX 控件”，您的浏览器须允许执行控件。");
	              return;
	          }
	      }
	       
	      try {
	          var m=1;
	          oXL.Visible = true;
	          oXL.ScreenUpdating=false;
	          //oXL.Calculation=-4135;
	          var oWB = oXL.Workbooks.Add;
	          var oSheet = oWB.ActiveSheet;
	          var xlsheet = oWB.Worksheets(1);
	          for(var i=oWB.Worksheets.count;i>1;i--){    //删除多余工作表
	              oWB.Worksheets(i).Delete();
	          }
	          for(var n=0;n<tables.length;n++){
	              var elTable = document.getElementById(tables[n]);
	              var oRangeRef = document.body.createTextRange();
	              oRangeRef.moveToElementText(elTable);
	              oRangeRef.execCommand("Copy");
	              oSheet.cells(m,1).select;
	              oSheet.Paste();    //此方式为直接粘贴，带格式
	              if (method == 0) {
	                  oSheet.cells.ClearFormats;
	                  //以下删除因表头分拆后产生的空行,一般表头不会超过5行,此处检查5行数据
	                  for(var delrow=1;delrow<5;delrow++){
	                      var isBlank=true;
	                      for(var col=1;col<=elTable.rows[0].cells.length;col++){
	                          if(oSheet.cells(m+1,col).value!="" && oSheet.cells(m+1,col).value!=undefined){
	                              isBlank=false;
	                              break;
	                          }
	                      }
	                      if(isBlank){
	                          oSheet.Rows(m+1).Delete;
	                      }
	                  }
	              }
	              m+=elTable.rows.length;
	          }
	          //oSheet.Cells.NumberFormatLocal = "@";//格式化数字时使用
	          n=oSheet.Shapes.count;
	          for(var i=1;i<=n;i++){
	              oSheet.Shapes.Item(1).Delete();        //因为每次删除都会使总数减少,所以删除n次第一个对象,也可以倒过来从大到小删除
	          }
	          oXL.Selection.CurrentRegion.Select;            //选择当前区域
	          oXL.Selection.Interior.Pattern = 0;            //设置底色为空
	          oXL.Selection.Borders.LineStyle = 1;        //设置单元格边框为实线
	         // oXL.Selection.ColumnWidth = 50;                //设置列宽
	          //oXL.Selection.RowHeight = 16;                //行高
	          oXL.Selection.WrapText=true; 				 //设置为自动换行*
	         // oXL.Selection.Columns.AutoFit;                //列宽自动适应
	          xlsheet.Columns("J").ColumnWidth = 60; 
	          xlsheet.Columns("F").ColumnWidth = 40; 
	          // xlsheet.Columns("A:Z").AutoFit;            //列宽自动适应
	          xlsheet.Rows(1).RowHeight = 40;
	          xlsheet.Rows("2:"+m).AutoFit;                //自动行高
	          xlsheet.Name=sheetname;
	          oSheet = null;
	          oWB = null;
	          appExcel = null;
	          //oXL.Calculation=-4105;
	          oXL.ScreenUpdating=true;
	          idTmr = window.setInterval("Cleanup();",1);     //释放Excel进程，回收内存空间，避免产生多个不会自己终止的Excel进程
	         }catch (e) {
	          idTmr = window.setInterval("Cleanup();",1);
	          alert(e.description);       
	      }
	  }
	
	  function starttoexcel(){
		  var id = $('.layui-show table')[0].id;
		  toExcel(id,'excel',1,10)
	  }
	
</script>
</html>